﻿using FarmSmartSleep.Common.Domain;
using FarmSmartSleep.Common.Domain.RBACFile;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Organ.API.Application.Commands.CottagesCommands;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace FarmSmartSleep.Organ.API.Controllers
{
    /// <summary>
    /// 栋舍控制器--API
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CottagesController : ControllerBase
    {

        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">中介者</param>
        public CottagesController(IMediator mediator)
        {
            this.mediator = mediator;
        }


        /// <summary>
        /// 添加栋舍信息
        /// </summary>
        /// <param name="cmd">添加栋舍信息请求对象</param>
        /// <returns>返回添加栋舍信息响应对象</returns>
        [HttpPost]
        public async Task<Result> CreateCottage(CottageCreateCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 栋舍查询方法（分页）
        /// </summary>
        /// <param name="cmd">栋舍查询方法请求对象</param>
        /// <returns>栋舍查询方法响应对象</returns>
        [HttpPost]
        public async Task<ResultPage<CottageListDto>> CottageList(CottageSearchCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 获取栋舍类型信息
        /// </summary>
        /// <param name="cmd">获取栋舍类型信息请求对象</param>
        /// <returns>栋舍类型信息响应对象</returns>
        [HttpPost]
        public async Task<ResultT<CottageType>> SearchCottageTypes(CottageTypeSearchCommand cmd)
        {
            return await mediator.Send(cmd);
        }


        /// <summary>
        /// 获取负责人（生产人）
        /// </summary>
        /// <param name="cmd">获取负责人（生产人）请求对象</param>
        /// <returns>获取负责人（生产人）响应对象</returns>
        [HttpPost]
        public async Task<ResultT<Employee>> SearchEmployees(EmployeeSearchCommand cmd)
        {
            return await mediator.Send(cmd);
        }


        /// <summary>
        /// 批量删除栋舍信息
        /// </summary>
        /// <param name="cmd">批量删除栋舍信息请求对象</param>
        /// <returns>批量删除栋舍信息响应对象</returns>
        [HttpDelete]
        public async Task<Result> AllDeleteCottages(CottageAllDeleteCommand cmd)
        {
            return await mediator.Send(cmd);
        }


        /// <summary>
        /// 反添栋舍信息方法
        /// </summary>
        /// <param name="cmd">反添栋舍信息请求对象</param>
        /// <returns>反添栋舍信息响应对象</returns>
        [HttpPost]
        public async Task<ResultT<Cottages>> DetailCottage(CottageDetailCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 修改栋舍信息
        /// </summary>
        /// <param name="cmd">修改栋舍信息请求对象</param>
        /// <returns>修改栋舍信息响应对象</returns>
        [HttpPut]
        public async Task<Result> UpdateCottage(CottageUpdateCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 获取栋舍下栏位信息
        /// </summary>
        /// <param name="cmd">获取栋舍下栏位信息请求对象</param>
        /// <returns>获取栋舍下栏位信息响应对象</returns>
        [HttpPost]
        public async Task<ResultPage<Fields>> SearchFields(FieldSearchCommand cmd)
        {
            return await mediator.Send(cmd);
        }


        /// <summary>
        /// 添加栏位信息
        /// </summary>
        /// <param name="request">添加栏位请求对象</param>
        /// <param name="cancellationToken"></param>
        /// <returns>添加栏位响应对象</returns>
        [HttpPost]
        public async Task<Result> CreateFields(FieldCreateCommand cmd)
        {
            return await mediator.Send(cmd);
        }


    }
}
